package com.his.controller;

import com.his.common.annotation.Log;
import com.his.common.core.controller.BaseController;
import com.his.common.core.domain.AjaxResult;
import com.his.common.core.page.TableDataInfo;
import com.his.common.enums.BusinessType;
import com.his.common.utils.poi.ExcelUtil;
import com.his.entity.dto.Register;
import com.his.service.IRegisterService;
import com.his.entity.vo.RegisterVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 挂号及退号Controller
 * 
 * @author lixue
 * @date 2025-09-05
 */
@RestController
@RequestMapping("/register/register")
public class RegisterController extends BaseController
{
    @Autowired
    private IRegisterService registerService;

    /**
     * 查询挂号及退号列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Register register)
    {
        startPage();
        List<RegisterVO> list = registerService.selectRegisterList(register);
        return getDataTable(list);
    }

    /**
     * 导出挂号及退号列表
     */
    @Log(title = "挂号及退号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Register register)
    {
        List<RegisterVO> list = registerService.selectRegisterList(register);
        ExcelUtil<RegisterVO> util = new ExcelUtil<RegisterVO>(RegisterVO.class);
        util.exportExcel(response, list, "挂号及退号数据");
    }

    /**
     * 获取挂号及退号详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(registerService.selectRegisterById(id));
    }

    /**
     * 新增挂号及退号
     */
    @Log(title = "挂号及退号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Register register)
    {
        return toAjax(registerService.insertRegister(register));
    }

    /**
     * 修改挂号及退号
     */
    @Log(title = "挂号及退号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Register register)
    {
        return toAjax(registerService.updateRegister(register));
    }

    /**
     * 删除挂号及退号
     */
    @Log(title = "挂号及退号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(registerService.deleteRegisterByIds(ids));
    }

    /**
     * 查询科室列表
     */
    @GetMapping("/dept/list")
    public AjaxResult deptList()
    {
        return success(registerService.deptList());
    }

    /**
     * 查询挂号级别列表
     */
    @GetMapping("/level/list")
    public AjaxResult levelList()
    {
        return success(registerService.levelList());
    }

    /**
     * 查询医生排班列表
     */
    @GetMapping("/doctor/schedule/list")
    public AjaxResult doctorScheduleList(@RequestParam("deptId") Long deptId,
                                         @RequestParam("visitDate") Date visitDate,
                                         @RequestParam("registLevelId") Long registLevelId)
    {
        return success(registerService.doctorScheduleList(deptId, visitDate, registLevelId));
    }

    /**
     * 挂号结算类别列表
     */
    @GetMapping("/settle/category/list")
    public AjaxResult settleCategoryList()
    {
        return success(registerService.settleCategoryList());
    }

    @GetMapping("/schedule/usedQuota")
    public AjaxResult scheduleUsedQuota(@RequestParam("deptId") Long deptId,
                                        @RequestParam("visitDate") Date visitDate,
                                        @RequestParam("registLevelId") Long registLevelId)
    {
        return success(registerService.scheduleUsedQuota(deptId, visitDate, registLevelId));
    }
}

